package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.entity.beautyescort.EscortBeautyDispatch;
import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.beautyescort.BeautyEscortModule;
import com.yanqu.road.server.manger.beautyescort.BeautyEscortMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.S_BEAUTY_ESCORT_GET_DART_REWARD_FROM_CROSS, desc = "领取走镖奖励")
public class BeautyEscortGetDartRewardCmdFromCross extends AbstractCommand {

    BeautyEscortProto.BeautyEscortGetDartRewardRespMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = BeautyEscortProto.BeautyEscortGetDartRewardRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(reqMsg.hasReward()) {
            List<EscortBeautyDispatch> dispatchList = BeautyEscortMgr.parseBeautyDispatch(reqMsg.getBeautyList());
            player.getModule(BeautyEscortModule.class).addDartReward(reqMsg.getReward(), reqMsg.getExp(), dispatchList, reqMsg.getDartId());

            //走镖红点
            BeautyEscortProto.CrossBeautyEscortRedDotReqMsg.Builder reqMsg = BeautyEscortProto.CrossBeautyEscortRedDotReqMsg.newBuilder();
            player.sendPacket(Protocol.C_BEAUTY_ESCORT_RED_DOT_SYNC, reqMsg);
        }
        player.sendPacket(Protocol.U_BEAUTY_ESCORT_GET_DART_REWARD, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
